<?php

namespace App\Wechat;

use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Psr16Cache;

class Init
{
    public function __construct()
    {
        $this->app = app('easywechat.official_account')->setAccessToken(new MyAccessToken());
    }
    public function getApp()
    {
        return $this->app;
    }

    public function handle($method,$url,$options=[])
    {
        $api=$this->getApp()->getClient();
        $response = $api->$method($url, $options);
        $wxResponse = json_decode($response->getContent(),true); // 这里会抛出异常

        if($response->isSuccessful()){
            return $wxResponse;
        }else{
            throw new \Exception($wxResponse);
        }
    }
}
